/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.velocityme.entity;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

/**
 *
 * @author rcrida
 */
@Entity
@NamedQueries( {
    @NamedQuery(name="findAllPersons",
                query="SELECT p FROM Person p WHERE p.deleted = FALSE ORDER BY p.name"),
    @NamedQuery(name="findPersonsBySearchAndTransition",
                query="SELECT DISTINCT ua.user.person FROM UserAccess ua," +
                "Search s, IN (s.searchLevels) l, IN (l.nodes) ln, " +
                "Transition t, IN (t.responsibleRoles) tr " +
                "WHERE s=:search AND t=:transition AND ua.role=tr AND ua.node=ln"),
    @NamedQuery(name="findPersonsBySearchGroupAndTransition",
                query="SELECT DISTINCT u.person FROM GroupAccess ga, IN (ga.group.users) u, " +
                "Search s, IN (s.searchLevels) l, IN (l.nodes) ln, " +
                "Transition t, IN (t.responsibleRoles) tr " +
                "WHERE s=:search AND t=:transition AND ga.role=tr AND ga.node=ln")/*,
    @NamedQuery(name="findBySearchAndRoles",
                query="SELECT DISTINCT ua.user.person FROM Search s, IN (s.searchLevels) l, IN (l.nodes) ln, UserAccess ua, TaskStateMachine t, IN (t.interestedRoles) tr, Role r, Node n WHERE s=:search AND t=:taskStateMachine AND ua.role=r AND r = tr AND ua.node=n AND n = ln"),
    @NamedQuery(name="findBySearchGroupAndRoles",
                query="SELECT DISTINCT u.person FROM Search s, IN (s.searchLevels) l, IN (l.nodes) ln, GroupAccess ga, IN (ga.group.users) u, TaskStateMachine t, IN (t.interestedRoles) tr, Role r, Node n WHERE s=:search AND t=:taskStateMachine AND ga.role=r AND r = tr AND ga.node=n AND n = ln")*/
})
public class Person extends Contactable {
    private static final long serialVersionUID = 1L;

    private String firstName;

    private String lastName;

    private String jobTitle;

    @OneToMany(mappedBy = "person")
    private Set<User> users = new HashSet<User>();

    public Person() {
    }

    public Person(Node parentNode, String firstName, String lastName, String description) {
        super(parentNode, firstName + " " + lastName, description);
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getJobTitle() {
        return jobTitle;
    }

    public String getLastName() {
        return lastName;
    }

    public Set<User> getUsers() {
        return users;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public void setJobTitle(String jobTitle) {
        this.jobTitle = jobTitle;
    }

    

}
